﻿using B.S.BasicData.Api.Write.Application.Command.Approval;
using B.S.BasicData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Api.Write.Controllers
{
    /// <summary>
    /// 审批控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class ApprovalController : ControllerBase
    {
        private readonly IMediator mediator;

        public ApprovalController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加请假申请
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
       
        public Task<ApiResult<int>> AddApproval(AddApprovalCommand request)
        {
            return mediator.Send(request);   
        }
        /// <summary>
        /// 修改请假申请
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<ApiResult<int>> UpdateApproval(UpdateApprovalCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 删除请假申请
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<ApiResult<int>> DelApproval(DelApprovalCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 修改审批状态
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<ApiResult<int>> UpdateApprovalState(UpdateApprovalStateCommand request)
        {
            return mediator.Send(request);
        }
    }
}
